<?php

class LaravelPDF extends FPDF {

    public $title = "";
    public $labels = "";
    public $data = "";

    function __construct() {
        parent::__construct('P', 'mm', 'A4');
    }

    function Header() {
        $this->SetFont('Times', '', 10);
        $this->Cell(170, 9, "Corporacion Canllahua S.A.C. - ".$this->title, 0, 0, 'L', false);
        $this->Cell(20, 9, date("Y/m/d"), 0, 0, 'R', false);
        $this->Ln(7);
    }

    function Footer() {
        $this->SetY(-15); //Position at 1.5 cm from bottom
        $this->SetFont('Arial', 'B', 8);
        $this->Cell(0, 10, $this->PageNo(), 0, 0, 'C');
    }

    function process() {
        $this->AddPage();
        $this->SetFont('Arial', 'B', 10);
        $this->Cell(0, 9, $this->title, 0, 0, 'C', false);
        $this->Ln(9);
        $this->SetFont('', 'B', '7.5');
        $this->SetFillColor(128, 128, 128);
        $this->SetTextColor(255);
        $this->SetDrawColor(92, 92, 92);
        $this->SetLineWidth(.3);


        foreach ($this->labels as $label) {
            $this->Cell($label[0], 7, $label[1], 1, 0, 'C', true);
        }
        $this->Ln();

        $this->SetFillColor(255, 255, 255);
        $this->SetTextColor(128);
        $this->SetDrawColor(92, 92, 92);
        //$j = 0;
        foreach ($this->data as $values) {
            $i = 0;
            foreach ($values as $value) {
                $this->Cell($this->labels[$i][0], 7, utf8_decode($value), 1, 0, $this->labels[$i][2], true);
                $i++;
            }
            //$j++;
            $this->Ln();
            /*if ($j == 35) {
                $this->AddPage();
                $j = 0;
            }*/
        }

        $file = str_replace(' ', '_', strtolower($this->title)) . ".pdf";
        $this->Output($file, "D");
    }

}
